package com.oc.claimobs.bb.screens;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.oc.claimobs.bb.ScreenFlow;
import com.oc.utils.Style;

public class ConfirmScreen extends MainScreen {
	private Bitmap backgroundBitmap;

	public ConfirmScreen() {
		super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_HORIZONTAL_SCROLL
				| MainScreen.NO_VERTICAL_SCROLLBAR
				| MainScreen.NO_HORIZONTAL_SCROLLBAR);

		init();
	}

	private void init() {

	  	// The background image.
		backgroundBitmap = Bitmap.getBitmapResource("img/title_back.png");

		VerticalFieldManager vfm = new VerticalFieldManager(
				VerticalFieldManager.NO_VERTICAL_SCROLL
						| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
						| VerticalFieldManager.USE_ALL_WIDTH
						| VerticalFieldManager.NON_FOCUSABLE
						| VerticalFieldManager.USE_ALL_HEIGHT) {

			// Override the paint method to draw the background image.
			public void paint(Graphics graphics) {
				// Draw the background image and then call paint.
				graphics.drawBitmap(0, 0, Style.getScreenWidht(), 40, backgroundBitmap, 0, 0);
				super.paint(graphics);
			}
		};

		//Boton
		ButtonField button = new ButtonField("  Volver al inicio  ", ButtonField.FOCUSABLE | ButtonField.FIELD_HCENTER);
		button.setMargin(30, 30, 0, 30);
		//button.setFocusListener(new TouchScreenButtonFocusChangeListener(this));
		button.setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				// Save
				Screen cscreen = ScreenFlow.getInstance().getCONFIRMA_PAGE();
				Screen screen = ScreenFlow.getInstance().getNext("");
				UiApplication.getUiApplication().pushScreen(screen);
				try {
					UiApplication.getUiApplication().popScreen(cscreen);
				} catch (IllegalArgumentException e) {
				}
				
			}
		});
		
		
		
        LabelField lbl_gracias = new LabelField();
        lbl_gracias.setText("Gracias por utilizar el sistema!");
        lbl_gracias.setMargin(60,18,0,18);
		vfm.add(lbl_gracias);
		// Add the manager to the screen.
		
		vfm.add(button);
		add(vfm);

	}

	
	protected boolean invokeAction(int action) {
		boolean handled = super.invokeAction(action);

		if (!handled) {
			switch (action) {
				case ACTION_INVOKE: // Trackball click.
				{
					return true;
				}
			}
		}
		return handled;
	}
	
	public void close() {
		this.setDirty(false);
		super.close();
	}
}
